package org.prism.coll;

import java.util.*;

public class CollectionsTest {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>();
        personList.addAll(Arrays.asList(
                new Person("张三",3),new Person("李四",4),
                new Person("王五",5),new Person("赵六",6),
                new Person("田七",7),new Person("赵八",8)));
        personList.forEach(System.out::print);
        System.out.println();
        Collections.reverse(personList);
//        Collections.shuffle(personList);
//        Collections.sort(personList, new Comparator<Person>() {
//            @Override
//            public int compare(Person o1, Person o2) {
//                return Integer.compare(o2.getAge(), o1.getAge());
//            }
//        });
//        Collections.swap(personList,1,5);
        personList.forEach(System.out::print);
//        System.out.println(Objects.toString(personList));
    }

}
class Person{
    private String name;
    private Integer age;

    public Person() {
    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Person)) return false;

        Person person = (Person) o;

        if (!Objects.equals(name, person.name)) return false;
        return Objects.equals(age, person.age);
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (age != null ? age.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}